home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / toolbox / fftplot.r < prev    next >
Text File  |  1994-04-25  |  1KB  |  50 lines

  1. //---------------------------------------------------------------------------
  2. //  fftplot.r
  3.  
  4. //  Syntax:    fftplot ( Y )
  5. //        fftplot ( Y , T )
  6.  
  7. //  Fftplot compute and plot the magnitude in dB and phase in degrees
  8. //  of the FFT data in Y
  9. //
  10. //  T = sampling period, if this parameter is not given it is assumed
  11. //      to be equal to one.
  12.  
  13. //  The magnitude and phase are returned in list elements `mag' and
  14. //  `ph' respectively. The values for the frequency scale are returned
  15. //  in list element `freq'. The magnitude and phase are truncated
  16. //  above the Nyquist frequency. If plotf exists, then a plot of the
  17. //  magnitude of Y (in dB) versus frequency is produced.
  18. //
  19. //---------------------------------------------------------------------------
  20.  
  21. fftplot = function ( Y, T, plotf )
  22. {
  23.   local (f, n, lab, labid, mag, ph, ly)
  24.  
  25.   lab = ["DIGITAL FREQUENCY / pi" , "FREQUENCY HERTZ"];
  26.   ly = log (Y[:]);
  27.   mag = 20 * real(ly) / log(10);
  28.   ph = imag (ly);
  29.   n = max (size (Y))/2;
  30.   f = ((0:n-1)/n)';
  31.   if (!exist (T)) 
  32.   { 
  33.     labid = 1;
  34.   else
  35.     f = 0.5*f/T;
  36.     labid = 2;
  37.   }
  38.  
  39.   if (exist (plotf))
  40.   {
  41.     plot ("set title 'MAGNITUDE'");
  42.     plot ("set xlabel '"+lab[labid]+"'");
  43.     plot ("set ylabel 'dB'");
  44.  
  45.     plot ( [f, mag[1:n] ] );
  46.   }
  47.  
  48.   return << freq = f; mag = mag[1:n]; ph = ph[1:n] >>
  49. };
  50.